<?php
class JYXml{
	function format($arr,$flag='result'){
		$sXml = "<?xml version='1.0'?>";
		if(!is_array($arr)||count($arr)==0){
			return $sXml."<".$flag."></".$flag.">";
		}
		$sXml .="<".$flag.">".self::encode($arr)."</".$flag.">";

		return $sXml;
	}

	function encode($arr){
		$sXml = "";
		if(!is_array($arr)||count($arr)==0){
			return "";
		}

		foreach($arr as $f=>$v){
			if(is_numeric($f)){
				$f = 'record';
			}
			if(!is_array($v)){
				$sXml .="<{$f}>{$v}</{$f}>";
				continue;
			}
			$sXml .="<{$f}>".self::encode($v)."</{$f}>";
		}
		return $sXml;
	}

	function decode($sXml){
		$xml = simplexml_load_string($sXml);
		return $xml;	
	}
}
?>